<template>
  <div class="app-container">
    <el-form :inline="true" ref="ruleForm"  :model="formInline" class="demo-form-inline">
       <el-form-item label="操作类型" prop="optType">
        <el-select v-model="formInline.optType" placeholder="操作类型">
          <el-option
            v-for="item in typeList"
            :label="item.label"
            :key="item.value"
            :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
       <el-form-item label="类型" prop="blackType">
        <el-select v-model="formInline.blackType" placeholder="类型">
         <el-option
            v-for="item in consts.BLACK_LIST_TYPE"
            :label="item.label"
            :key="item.value"
            :value="item.value"
            v-if="item.value!=''"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="值" prop="blackTitle">
        <el-input v-model="formInline.blackTitle" placeholder="请输入值" @keyup.enter.native="toSearch" :readonly="!formInline.blackType"></el-input>
      </el-form-item>
      <el-form-item label="调整前群组" prop="oldLevel">
        <el-select v-model="formInline.oldLevel" multiple collapse-tags placeholder="调整前群组" style="width:200px">
          <el-option
            v-for="item in levelList"
            :label="item.levelName"
            :key="item.levelId"
            :value="item.levelId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="调整后群组" prop="level">
        <el-select v-model="formInline.level" multiple  collapse-tags placeholder="调整后群组" style="width:200px">
          <el-option
            v-for="item in levelList"
            :label="item.levelName"
            :key="item.levelId"
            :value="item.levelId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="操作人" prop="creator">
        <el-input v-model="formInline.creator" placeholder="请输入操作人" @keyup.enter.native="toSearch"></el-input>
      </el-form-item>
      <el-form-item>
        <el-col>
          <el-form-item prop="time" label="调整时间">
            <el-date-picker
              v-model="formInline.time"
              type="datetimerange"
              align="right"
              unlink-panels
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd HH:mm:ss"
              :default-time="['00:00:00', '23:59:59']"
              :picker-options="pickerWeekStep">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-form-item>
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="toSearch">搜索
      </el-button>
      <el-button @click="selfResetForm('ruleForm')">重置</el-button>
    </el-form>
  </div>

</template>
<script>
import { form, grid, pickerOption } from '@/build';


export default {
  name: 'form-filter',
  mixins: [form, grid, pickerOption],
  props: ['levelList'],
  data() {
    return {
      // levelList: [],
      typeList: [
        { label: '全部', value: undefined },
        { label: '手动添加', value: 0 },
        { label: '调整等级', value: 1 },
        { label: '调整关联等级', value: 2 },
      ],
      formInline: {
        time: [
          moment().format('YYYY-MM-DD 00:00:00'),
          moment().format('YYYY-MM-DD 23:59:59'),
        ],
        optType: undefined, // 操作类型
        blackType: '', // 黑名单类型
        blackTitle: '', // 值
        creator: '', // 操作人
        level: [], // 群组
        oldLevel: [], // 调整前等级
        page: 1,
        size: 20,
      },
    };
  },
  watch: {
    levelList(val) {
      if (val.length > 0) {
        this.formInline.level = [];
        this.formInline.oldLevel = [];
        val.forEach((item) => {
          this.formInline.level.push(item.levelId);
          this.formInline.oldLevel.push(item.levelId);
        });
      }
    },
  },
  methods: {
    toSearch() {
      this.$emit('on-filter', this.formInline);
    },
    selfResetForm(formName) {
      this.resetForm(formName);
      this.levelList.forEach((item) => {
        this.formInline.level.push(item.levelId);
        this.formInline.oldLevel.push(item.levelId);
      });
      this.$emit('on-filter', this.formInline);
    },
  },
  mounted() {
    // window.addEventListener('keyup', (e) => {
    //   const event = e || window.event;
    //   const code = event.keyCode || event.which || event.charCode;
    //   if (code == 13) {
    //     this.toSearch();
    //   }
    // });
  },
};
</script>

<style lang="scss" scoped>
 .mgtop{margin-top:30px}
</style>
